package com.wiz.weixin.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.wiz.weixin.TO.SettingsConfigTO;
import com.wiz.weixin.mapper.SettingsConfigMapper;
import com.wiz.weixin.service.SettingsService;

@Service("settingsService")
public class SettingsServiceImpl implements SettingsService {

	@Resource
	private SettingsConfigMapper settingsConfigMapper;
	
	@Override
	public Map<Integer,Integer> listSetting(String openId) {
		Map<Integer,Integer> map = new HashMap<Integer,Integer>();
		SettingsConfigTO setting = null;
		List<SettingsConfigTO> list = settingsConfigMapper.listSetting(openId);
		for(int i=0; i<list.size(); i++){
			setting = list.get(i);
			map.put(setting.getType(), setting.getStatus());
		}
		return map;
	}

	@Override
	public int save(SettingsConfigTO settingsConfigTO)throws Exception {
		// TODO Auto-generated method stub
		settingsConfigMapper.remove(settingsConfigTO.getOpenId(), settingsConfigTO.getType());
		return settingsConfigMapper.save(settingsConfigTO);
	}

}
